home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1995 #5 & #6 / Amiga Plus CD - 1995 - No. 5 and 6.iso / pd / netz / dcc / processfile.rexx < prev    next >
OS/2 REXX Batch file  |  1995-07-22  |  8KB  |  256 lines

  1. /* $VER: ProcessFile.rexx 0.14 (19.3.95) 
  2.  * process a file according to the extension */
  3. /* Authors Osma Ahvenlampi, Michael Van Elst, Dan Murrell Jr. 
  4.  * View a file after de-archiving enhancement by Alejandro Garza */
  5.  
  6. /* This is the program used to view the file if no match is found */
  7. file.default = "SYS:Utilities/MultiView"
  8.  
  9. /* If this is set to 1, the user will be asked whether he wants to delete
  10.  * the file after it has been processed */
  11. file.delete = 1
  12.  
  13. /* If this is set to 1, the user will be prompted if he/she wants to view
  14.  * any of the files in the archive after unpacking */
  15. file.arcview = 1
  16.  
  17. /* list of supported archivers */
  18. file.archive = "LHA LZH GZ Z ZIP DMS LZX"
  19.  
  20. /* where you would like the archive unpacked by default */
  21. file.unpackdir = "RAM:"
  22.  
  23. /* full paths to known (un)packers */
  24. archiver.lha = "LhA"
  25. archiver.gzip = "GZip"
  26. archiver.zip = "UnZip"
  27. archiver.lzx = "LZX"
  28.  
  29. /* next is the list of extensions and the programs used to show them
  30.  * list the extensions in upper case */
  31. file.1.type = "ILBM HAM GIF"
  32. file.1.viewer = "FastView >NIL:"
  33. file.2.type = "WAV AU 8SVX"
  34. file.2.viewer = "Play16 >NIL:" /* LOTS better than OPlay... */
  35. file.3.type = "JPG JPEG"
  36. file.3.viewer = "SYS:Utilities/FJPEG >NIL:"
  37. file.4.type = "GUIDE TXT DOC"
  38. file.4.viewer = "SYS:Utilities/MultiView"
  39. file.5.type = "MOD MED"
  40. file.5.viewer = "SYS:Utilities/Player NODETACH MODULES"
  41. file.6.type = "MPG MPEG"
  42. file.6.viewer = "mp -dither ham6"
  43.  
  44. /* this is the number of the last type */
  45. file.num = 6
  46.  
  47. /* get filename */
  48. parse arg '"' completename '"' '"' pubscreen '"'
  49.  
  50. if completename="" then
  51.     parse arg completename
  52.  
  53. if ~exists(completename) then exit
  54.  
  55. if pubscreen="" then
  56.     pubscreen = "Workbench"
  57.  
  58. viewed = 0
  59. processed = 0
  60.  
  61. if ~show(l, 'rexxsupport.library') then do
  62.     if ~addlib('rexxsupport.library', 0, -30) then do
  63.         address command 'C:RequestChoice PUBSCREEN="'pubscreen'" TITLE="Process File Error" BODY="Could not execute macro*nlibs:rexxsupport.library not found" GADGETS="OK" >NIL:'
  64.         exit 10
  65.     end
  66. end
  67.  
  68. call CheckExt
  69.  
  70. /* test it against known archivers/packers */
  71. if (extension ~= "") & (find( file.archive, extension ) > 0) then do
  72.     viewed = 1
  73.     call UnPack
  74. end
  75.  
  76. /* test it against known file types */
  77. if ~viewed & (extension ~= "") then
  78.     do i = 1 to file.num while ~viewed
  79.         if find( file.i.type, extension ) > 0 then do
  80.             viewed = 1
  81.             address command file.i.viewer '"'completename'"'
  82.             if rc = 0 then
  83.                 processed = 1
  84.         end
  85.     end
  86.  
  87. if ~viewed then do
  88.     /* if the type wasn't recognised, try the default viewer on it */
  89.     address command file.default '"'completename'"'
  90.     if rc = 0 then
  91.         processed = 1
  92. end
  93.  
  94. call DeleteFile
  95.     
  96. exit
  97.  
  98. UnPack:
  99.     if (extension = "LHA") | (extension = "LZH") then do
  100.         address command archiver.lha 'v "'completename'" >T:LhaContents.tmp'
  101.         address command file.default 'T:LhaContents.tmp'
  102.         call delete('T:LhaContents.tmp')
  103.  
  104.         address command 'RequestChoice PUBSCREEN="'pubscreen'" TITLE="Process File" BODY="Un-LHA file 'completename'?" GADGETS="Yes|No" >T:reqchoice.unlha'
  105.     
  106.         call open(choicefile, 'T:reqchoice.unlha', 'R')
  107.         answer = readch(choicefile, 1)
  108.         call close(choicefile)
  109.         call delete('T:reqchoice.unlha')
  110.  
  111.         if answer = '1' then do
  112.             address command 'RequestFile SAVEMODE DRAWER="'file.unpackdir'" TITLE="Choose destination directory" NOICONS DRAWERSONLY PUBSCREEN="'pubscreen'" >T:req.drawer'
  113.  
  114.             call open(choicefile, 'T:req.drawer', 'R')
  115.             file.unpackdir = readln(choicefile)
  116.             call close(choicefile)
  117.             call delete('T:req.drawer')
  118.     
  119.             if length(answer) > 0 then do
  120.                 address command archiver.lha 'x "'completename'" 'file.unpackdir
  121.                 processed = 1
  122.             end
  123.         end
  124.     end
  125.  
  126.     if (extension = "LZX") then do
  127.         address command archiver.lzx 'v "'completename'" >T:LZXContents.tmp'
  128.         address command file.default 'T:LZXContents.tmp'
  129.         call delete('T:LZXContents.tmp')
  130.  
  131.         address command 'RequestChoice PUBSCREEN="'pubscreen'" TITLE="Process File" BODY="Un-LZX file 'completename'?" GADGETS="Yes|No" >T:reqchoice.unlzx'
  132.     
  133.         call open(choicefile, 'T:reqchoice.unlzx', 'R')
  134.         answer = readch(choicefile, 1)
  135.         call close(choicefile)
  136.         call delete('T:reqchoice.unlzx')
  137.  
  138.         if answer = '1' then do
  139.             address command 'RequestFile SAVEMODE DRAWER="'file.unpackdir'" TITLE="Choose destination directory" NOICONS DRAWERSONLY PUBSCREEN="'pubscreen'" >T:req.drawer'
  140.  
  141.             call open(choicefile, 'T:req.drawer', 'R')
  142.             file.unpackdir = readln(choicefile)
  143.             call close(choicefile)
  144.             call delete('T:req.drawer')
  145.     
  146.             if length(answer) > 0 then do
  147.                 address command archiver.lzx 'x "'completename'" 'file.unpackdir
  148.                 processed = 1
  149.             end
  150.         end
  151.     end
  152.  
  153.     if (extension = "ZIP") then do
  154.         address command archiver.zip '-v "'completename'" >T:ZIPContents.tmp'
  155.         address command file.default 'T:ZIPContents.tmp'
  156.         call delete ('T:ZIPContents.tmp')
  157.  
  158.         address command 'RequestChoice PUBSCREEN="'pubscreen'" TITLE="Process File" BODY="UnZIP file 'completename'?" GADGETS="Yes|No" >T:reqchoice.unZIP'
  159.  
  160.         call open(choicefile, 'T:reqchoice.unZIP', 'R')
  161.         answer = readch(choicefile, 1)
  162.         call close(choicefile)
  163.         call delete('T:reqchoice.unZIP')
  164.  
  165.         if answer = '1' then do
  166.             address command 'RequestFile SAVEMODE DRAWER="'file.unpackdir'" TITLE="Choose destination directory" NOICONS DRAWERSONLY PUBSCREEN="'pubscreen'" >T:req.drawer'
  167.  
  168.             call open(choicefile, 'T:req.drawer', 'R')
  169.             file.unpackdir = readln(choicefile)
  170.             call close(choicefile)
  171.             call delete('T:req.drawer')
  172.     
  173.             if length(answer) > 0 then do
  174.                 address command archiver.zip '"'completename'" -d 'file.unpackdir
  175.                 processed = 1
  176.             end
  177.         end
  178.     end
  179.     
  180.     /* Ask if the user wants to view any of the files, if file.arcview == 1 */
  181.     if processed & file.arcview then do
  182.         call DeleteFile
  183.         file.delete = 0        /* don't touch the unpacked files... */
  184.         address command 'RequestChoice PUBSCREEN="'pubscreen'" TITLE="Process File" BODY="View a file from the archive?" GADGETS="Yes|No" >T:reqchoice.arcview'
  185.  
  186.         call open(choicefile, 'T:reqchoice.arcview', 'R')
  187.         answer = readln(choicefile)
  188.         call close(choicefile)
  189.         call delete('T:reqchoice.arcview')
  190.  
  191.         if answer = '1' then do
  192.             address command 'RequestFile DRAWER='file.unpackdir' TITLE="Choose file to view" NOICONS PUBSCREEN="'pubscreen'" >T:req.arcfile'
  193.  
  194.             call open(choicefile, 'T:req.arcfile', 'R')
  195.             answer = readln(choicefile)
  196.             call close(choicefile)
  197.             call delete('T:req.arcfile')
  198.  
  199.             parse var answer '"'completename'"'
  200.             call CheckExt
  201.             viewed = 0
  202.             processed = 0
  203.         end
  204.         return
  205.     end
  206.     
  207.     if (extension = "GZ") | (extension = "Z") then do
  208.         if index(upper(completename),".TAR.GZ") = 0 then do
  209.             address command archiver.gzip '-d "'completename'"'
  210.             viewed = 0
  211.             completename = filename
  212.             call CheckExt
  213.         end
  214.         else
  215.             viewed = 1
  216.     end
  217.     
  218.     if (extension = "DMS") then do
  219.         viewed = 1
  220.     end
  221.  
  222.     return
  223.  
  224. CheckExt:
  225.     /* find position of the last period, if any, to set off the file extension */
  226.     dot = lastpos(".", completename)
  227.  
  228.     if (dot > 0) then do
  229.         /* there is an extension.. put it in another variable and make it upper case */
  230.         filename = left(completename, dot-1)
  231.         extension = upper(substr(completename, dot+1))
  232.     end
  233.     else do
  234.         filename = completename
  235.         extension = ""
  236.     end
  237.  
  238.     return
  239.  
  240. DeleteFile:
  241.     if processed & file.delete & exists(completename) then do 
  242.         address command 'RequestChoice PUBSCREEN="'pubscreen'" TITLE="Process File" BODY="Delete file 'completename'?" GADGETS="Yes|No" >T:reqchoice.delete'
  243.     
  244.         call open(choicefile, 'T:reqchoice.delete', 'R')
  245.         answer = readch(choicefile, 1)
  246.         call close(choicefile)
  247.         call delete('T:reqchoice.delete')
  248.         
  249.         if answer = '1' then do
  250.             call delete(completename)
  251.     /*        address command 'C:RequestChoice >NIL: PUBSCREEN="'pubscreen'" TITLE="Process File" BODY="'completename' deleted" GADGETS="OK"' */
  252.         end
  253.     end
  254.  
  255.     return
  256.